//
//  XOHLoginVC.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/9/29.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import RxSwift

class XOHLoginVC: UIViewController {
    
    @IBOutlet weak var usernameTF: UITextField!
    @IBOutlet weak var usernameHintLB: UILabel!
    
    @IBOutlet weak var passwordTF: UITextField!
    @IBOutlet weak var passwordHintLB: UILabel!
    
    @IBOutlet weak var sumbitBT: UIButton!
    
    let disposeBag = DisposeBag()
    
    private var vm: XOHLoginVM!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        vm = XOHLoginVM(username: usernameTF.rx.text.orEmpty.asObservable(), password: passwordTF.rx.text.orEmpty.asObservable())
        
//        vm.usernameValid.bind(to: passwordTF.rx.isEnabled).disposed(by: disposeBag)
        vm.usernamErrorHintValid.bind(to: usernameHintLB.rx.isHidden).disposed(by: disposeBag)
        
        vm.passwordErrorHintValid.bind(to: passwordHintLB.rx.isHidden).disposed(by: disposeBag)
//        vm.passwordValid.bind(to: passwordHintLB.rx.isHidden).disposed(by: disposeBag)
        
        vm.everythingValid.bind(to: sumbitBT.rx.isEnabled).disposed(by: disposeBag)
        
        sumbitBT.rx.tap.subscribe(onNext: { [weak self] in
            self?.vm.sumbit()
        }).disposed(by: disposeBag)

        // Do any additional setup after loading the view.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
